package com.dagit.network;

import java.io.IOException;
import java.net.InetAddress;
import java.net.Proxy;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;

import com.dagit.core.pool.CommunicationException;

public class SocketImpl extends Socket {
	private LocalClientSocketPool localClientSocketPool;

	public SocketImpl() {
	}

	public SocketImpl(Proxy proxy) {
		super(proxy);
	}

	public SocketImpl(java.net.SocketImpl impl) throws SocketException {
		super(impl);
	}

	public SocketImpl(String host, int port) throws UnknownHostException,
			IOException {
		super(host, port);
	}

	public SocketImpl(InetAddress address, int port) throws IOException {
		super(address, port);
	}

	public SocketImpl(String host, int port, InetAddress localAddr,
			int localPort) throws IOException {
		super(host, port, localAddr, localPort);
	}

	public SocketImpl(InetAddress address, int port, InetAddress localAddr,
			int localPort) throws IOException {
		super(address, port, localAddr, localPort);
	}
	
	
	
	public LocalClientSocketPool getLocalClientSocketPool() {
		return localClientSocketPool;
	}

	public void setLocalClientSocketPool(LocalClientSocketPool localClientSocketPool) {
		this.localClientSocketPool = localClientSocketPool;
	}

	
	@Override
	public synchronized void close() throws IOException {
		if (localClientSocketPool != null){
			try {
				localClientSocketPool.checkIn(this);
			} catch (CommunicationException e) {
				throw new IOException(e);
			}
		}else{
			super.close();
		}
	}
	

}
